import request from '@/utils/request'

export function getModels(query) {
  return new Promise((resolve, reject) => {
    request({
      url: '/got_model_manage',
      method: 'get',
      params: {
        user_id: query.id,
        limit: query.filters.perPage,
        page: query.filters.page,
      },
    })
      .then((res) => {
        console.log('hhh')
        console.log(res)
        resolve({
          code: res.code,
          data: res.data.map((item) => ({
            id: item.model_id,
            name: item.model_name,
            protect_type: item.model_protect,
            model_type: item.model_type,
            description: item.model_describe,
          })),
          pagination: {
            page: res.pagination.page,
            perPage: res.pagination.perpage,
            total: res.pagination.total,
          },
        })
      })
      .catch((error) => {
        reject(error)
      })
  })
}

export function createModel(data) {
  return request({
    url: '/upload_model',
    method: 'post',
    params: {
      user_id: data.id,
      model_name: data.name,
      model_type: data.model_type,
      model_describe: data.description,
      model_protect: data.protect_type,
    },
  })
}
